home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / 12CUTILS.LZH / SCRATT.C < prev    next >
Text File  |  1984-05-04  |  3KB  |  97 lines

  1. /*                         *** scratt.c ***                          */
  2. /*                                                                   */
  3. /* IBM - PC microsoft "C" under PC-DOS                               */
  4. /*                                                                   */
  5. /* Function to turn on and off in a toggle switch manner various     */
  6. /* screen attributes such as BOLD, blink, reverse video, etc.        */
  7. /* Returns a 0 if successful or a -1 if not.                         */
  8. /*                                                                   */
  9. /* Written by L. Cuthbertson, April 1984.                            */
  10. /*                                                                   */
  11. /*********************************************************************/
  12. /*                                                                   */
  13.  
  14. #define NULL    '\000'
  15. #define POUND    '#'
  16.  
  17. int scratt(iatt)
  18. int iatt;
  19. {
  20.     extern char SGR[];
  21.     char catt[3],command[20];
  22.     static int switches[9] = {0,0,0,0,0,0,0,0,0};
  23.     int i,j,inpos,outpos;
  24.     int savpos,gotone;
  25.  
  26.     /* error check */
  27.     if (iatt<0 || iatt>8)
  28.         return(-1);
  29.  
  30.     /* toggle selected switch */
  31.     if (iatt == 0) {
  32.         for(i=0;i<9;i++) {
  33.             switches[i] = 0;
  34.         }
  35.     } else {
  36.         switches[iatt] = !(switches[iatt]);
  37.     }
  38.  
  39.     /* initialize screen controls */
  40.     scrinit();
  41.  
  42.     /* turn all attributes off ***********************************/
  43.     catt[0] = '0';        /* turn all attributes off */
  44.     catt[1] = NULL;
  45.  
  46.     /* build control sequence */
  47.     inpos = 0;    /* position in control line */
  48.     outpos = 0;    /* position in command line */
  49.  
  50.     while (SGR[inpos] != POUND)
  51.         command[outpos++] = SGR[inpos++];
  52.  
  53.     for (i=0;catt[i] != NULL;i++)
  54.         command[outpos++] = catt[i];
  55.  
  56.     inpos++;
  57.     while(SGR[inpos] != NULL)
  58.         command[outpos++] = SGR[inpos++];
  59.  
  60.     command[outpos] = NULL;
  61.  
  62.     /* write command to screen */
  63.     writes(command);
  64.  
  65.     /* turn selected attibutes on ********************************/
  66.     if (iatt != 0) {
  67.         gotone = 0;
  68.  
  69.         /* loop through switches */
  70.         for(j=1;j<9;j++) {
  71.             if (switches[j] != 0) {
  72.  
  73.                 /* got an attribute */
  74.                 gotone++;
  75.                 inpos = 0;
  76.                 outpos = 0;
  77.                 sprintf(catt,"%d",j);
  78.  
  79.                 while (SGR[inpos] != POUND)
  80.                     command[outpos++] = SGR[inpos++];
  81.  
  82.                 for (i=0;catt[i] != NULL;i++)
  83.                     command[outpos++] = catt[i];
  84.  
  85.                 inpos++;
  86.                 while(SGR[inpos] != NULL)
  87.                     command[outpos++] = SGR[inpos++];
  88.  
  89.                 command[outpos] = NULL;
  90.                 writes(command);
  91.             }
  92.         }
  93.     }
  94.  
  95.     return(0);
  96. }
  97.